Page({
  data:{
    code: -1,
    list: [
      {
        alphabet: '#', 
        datas: [
          { 
            id: 0,
            title: "1型糖尿病",
            status: 0
          }, 
          { 
            id: 1,
            title: "ADH分泌过多综合征",
            status: 0
          }, 
        ]
      },
      {
        alphabet: 'A', 
        datas: [
          {
            id: 2,
            title: "阿尔茨海默病性痴呆",
            status: 0
          }, 
          {
            id: 3,
            title: "阿斯匹林不耐受三联症",
            status: 0
          }, 
          {
            id: 4,
            title: "癌肿性关节炎",
            status: 0
          }, 
        ]},
      {
        alphabet: 'B', 
        datas: [
          { 
            id: 5,
            title: "巴斯德菌肺炎",
            status: 0
          }, 
          { 
            id: 6,
            title: "白癜风",
            status: 0
          }, 
          {
            id: 7,
            title: "白内障",
            status: 0
          }, 
          {
            id: 8,
            title: "白癜风胶囊",
            status: 0
          }, 
          {
            id: 9,
            title: "白血病",
            status: 0
          }, 
          {
            id: 10,
            title: "败血症",
            status: 0
          }, 
          {
            id: 11,
            title: "伴齿状突骨折的寰枢椎前脱位",
            status: 0
          }, 
          {
            id: 12,
            title: "伴有虹膜睫状体炎的继发性青光眼",
            status: 0
          }, 
          {
            id: 13,
            title: "苯海拉明中毒",
            status: 0
          }, 
        ]},
      {
        alphabet: 'C', 
        datas: [
          { 
            id: 14,
            title: "产后抑郁症",
            status: 0
          }, 
          { 
            id: 15,
            title: "肠道病毒71型手足口病",
            status: 0
          }, 
          {
            id: 16,
            title: "肠道菌群失调症",
            status: 0
          }, 
          {
            id: 17,
            title: "肠绞痛",
            status: 0
          }, 
          {
            id: 18,
            title: "肠扭转综合征",
            status: 0
          }, 
          {
            id: 19,
            title: "肠系膜淋巴结结核",
            status: 0
          }, 
          {
            id: 20,
            title: "成人多囊肾",
            status: 0
          }, 
        ]},
      {
        alphabet: 'D', 
        datas: [
          { 
            id: 21,
            title: "丹毒丝菌病",
            status: 0
          }, 
          { 
            id: 22,
            title: "单纯红细胞再障性贫血",
            status: 0
          }, 
          {
            id: 23,
            title: "单房性骨囊肿",
            status: 0
          }, 
          {
            id: 24,
            title: "胆固醇肺炎",
            status: 0
          }, 
          {
            id: 25,
            title: "胆管炎",
            status: 0
          }, 
          {
            id: 26,
            title: "低钾血症",
            status: 0
          }, 
        ]},
      {
        alphabet: 'E', 
        datas: [
          { 
            id: 27,
            title: "恶性组织细胞病",
            status: 0
          }, 
          { 
            id: 28,
            title: "儿童糖尿病",
            status: 0
          }, 
          {
            id: 29,
            title: "耳后骨膜下脓肿",
            status: 0
          }, 
        ]},
      {
        alphabet: 'F', 
        datas: [
          { 
            id: 30,
            title: "放射性肠炎",
            status: 0
          }, 
        ]},
      {
        alphabet: 'G', 
        datas: [
          { 
            id: 31,
            title: "高碘性甲状腺肿",
            status: 0
          }, 
        ]},
      {
        alphabet: 'H', 
        datas: [
          { 
            id: 32,
            title: "黑棘皮病",
            status: 0
          }, 
        ]},
      {alphabet: 'I', 
      datas: [

      ]},
      {alphabet: 'J', 
      datas: [
        { 
          id: 33,
          title: "急性出血性坏死性小肠炎",
          status: 0
        }, 
        { 
          id: 34,
          title: "急性坏死出血性脑脊髓炎",
          status: 0
        }, 
      ]},
      {alphabet: 'K', 
      datas: [
        { 
          id: 35,
          title: "开放性气胸",
          status: 0
        }, 
      ]},
      {alphabet: 'L', 
      datas: [
        { 
          id: 36,
          title: "老年人肺气肿",
          status: 0
        }, 
      ]},
      {alphabet: 'M', 
      datas: [
        { 
          id: 37,
          title: "马拉色菌病",
          status: 0
        }, 
      ]},
      {alphabet: 'N', 
      datas: [
        { 
          id: 38,
          title: "脑动脉硬化伴发的精神障碍",
          status: 0
        }, 
      ]},
      {alphabet: 'O', 
      datas: [

      ]},
      {alphabet: 'P', 
      datas: [
        { 
          id: 39,
          title: "盆腔炎",
          status: 0
        }, 
        { 
          id: 40,
          title: "皮肤B细胞淋巴样结节型增生",
          status: 0
        }, 
      ]},
      {alphabet: 'Q', 
      datas: [
        { 
          id: 41,
          title: "气单胞菌肺炎",
          status: 0
        }, 
      ]},
      {alphabet: 'R', 
      datas: [
        { 
          id: 42,
          title: "热感冒",
          status: 0
        }, 
      ]},
      {alphabet: 'S', 
      datas: [
        { 
          id: 43,
          title: "色素斑",
          status: 0
        }, 
      ]},
      {alphabet: 'T', 
      datas: [
        { 
          id: 44,
          title: "糖尿病皮肤感染",
          status: 0
        }, 
      ]},
      {alphabet: 'U', 
      datas: [

      ]},
      {alphabet: 'V', 
      datas: [

      ]},
      {alphabet: 'W', 
      datas: [
        { 
          id: 45,
          title: "外伤性硬脑膜下积液",
          status: 0
        }, 
        { 
          id: 46,
          title: "微小病毒感染",
          status: 0
        }, 

      ]},
      {alphabet: 'X', 
      datas: [
        { 
          id: 47,
          title: "先天性肠旋转不良",
          status: 0
        }, 
        { 
          id: 48,
          title: "先天性主动脉瓣窦动脉瘤破裂",
          status: 0
        }, 
      ]},
      {alphabet: 'Y', 
      datas: [
        { 
          id: 49,
          title: "药物相关性免疫性溶血性贫血",
          status: 0
        }, 
      ]},
      {alphabet: 'Z', 
      datas: [
        { 
          id: 50,
          title: "中枢神经系统肉芽肿性血管炎",
          status: 0
        }, 
      ]},
    ],
    content_array: [],
    alpha: '',
    windowHeight: '',
    input_text: "", //搜索框的值
    history: false, //显示历史记录
    noneview: false, //显示未找到提示
    content_list: false, //显示列表
    historyArray: [], //历史记录数组,
    newArray: [], //添加历史记录数组
  },

  //跳转至详情
  goto_xq: function(e){
    console.log(e.currentTarget.dataset.id)
    var code = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: '../cbxq/cbxq'
    })
    wx.setStorage({
      key: 'disease_code',
      data: code,
    })
  },
  //清除历史记录
  cleanhistory: function(e) {
    this.setData({
      history: false, //隐藏历史记录
      historyArray: [], //清空历史记录数组
      newArray: [],
      input_text: "" //清空搜索框
    })
  },
  //搜索
  search: function(e) {
    var searchtext = this.data.input_text; //搜索框的值
    var sss = true;
    let a='content_array.status';
    this.setData({
      content_list: false, //显示列表
    })
    var content_array=[]
    for(const element of this.data.list){
      for(const element2 of element.datas)
        content_array.push(element2)
    }
    if (searchtext != "") {
      //将搜索框的值赋给历史数组
      this.data.historyArray.push(searchtext);
      //模糊查询 循环查询数组中的title字段
      for (var index in content_array) {
        var num = content_array[index].title.indexOf(searchtext);
        let temp = 'content_array[' + index + '].status';
        if (num != -1) { //不匹配的不显示
          this.setData({
            [temp]: 1,
          })
          sss = false //隐藏未找到提示
        }
        console.log()
      }
      this.setData({
        history: false, //隐藏历史记录
        noneview: sss, //隐藏未找到提示
        content_list: true, //显示列表
        newArray: this.data.historyArray, //给新历史记录数组赋值
        content_array: content_array
      })
    } else {
      this.setData({
        //noneview: true, //显示未找到提示
        content_list: false, //隐藏列表
        history: false, //隐藏历史记录
      })
    }
  },

  //搜索框的值
  search_input: function(e) {
    //当删除input的值为空时
    if (e.detail.value == "") {
      this.setData({
        history: true, //显示历史记录
        content_list: false, //隐藏列表
        noneview:false,
      });
      //所有列表的状态改为0
      for (var index in this.data.content_array) {
        let temp = 'content_array[' + index + '].status';
        this.setData({
          [temp]: 0,
        })
      }
    }
    this.setData({
      input_text: e.detail.value
    })
  },

  //点击历史记录赋值给搜索框
  textfz: function(e) {
    this.setData({
      input_text: e.target.dataset.text
    })
  },

  onLoad(options){
    try {
      var res = wx.getSystemInfoSync()
      this.windowHeight = res.windowHeight
      console.log(this.windowHeight)
      this.apHeight = 16;
      this.offsetTop = 80;
      console.log(this.apHeight);
      console.log(this.offsetTop)
      this.setData({windowHeight: res.windowHeight + 'px'})
    } catch (e) {
      
    }
  },
  handlerAlphaTap(e) {
    console.log(e)
    let {ap} = e.target.dataset;
    this.setData({alpha: ap});
  },
  touchMove(e) {
    console.log(e)
    console.log(this.offsetTop)
    let {list} = this.data;
    console.log(list)
    console.log(this.data.alphabet)
    let moveY = e.touches[0].clientY;
    let rY = moveY - this.offsetTop;
    if(rY >= 0) {
      let index = Math.ceil((rY - this.apHeight)/ this.apHeight);
      if(0 <= index < list.length) {
        let nonwAp = list[index];
        nonwAp && this.setData({alpha: nonwAp.alphabet});
      } 
    }
  }
})

